using System.Windows;
using System.Windows.Controls;

namespace Profit.Controls
{
    public sealed class FixedGridViewColumn : GridViewColumn
    {

        static FixedGridViewColumn()
        {
            WidthProperty.OverrideMetadata(typeof(FixedGridViewColumn), new FrameworkPropertyMetadata(null, new CoerceValueCallback(OnCoerceWidth)));
        }

        public static readonly DependencyProperty FixedWidthProperty = DependencyProperty.Register("FixedWidth", typeof(double), typeof(FixedGridViewColumn), new FrameworkPropertyMetadata(double.NaN, new PropertyChangedCallback(OnFixedWidthChanged)));


        public double FixedWidth
        {
            get { return (double)GetValue(FixedWidthProperty); }
            set { SetValue(FixedWidthProperty, value); }
        }


        private static object OnCoerceWidth(DependencyObject o, object baseValue)
        {
            var fwc = o as FixedGridViewColumn;
            if (fwc != null)
                return fwc.FixedWidth;

            return 0.0;
        }

        private static void OnFixedWidthChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var fwc = o as FixedGridViewColumn;
            if (fwc != null)
                fwc.CoerceValue(WidthProperty);
        }

    }

}
